package com.itheima.services;

import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServicesA implements EmpServices{
    @Autowired
    public EmpMapper empMapper;

    @Override
    public User Elogin(User user) {
        User user1=empMapper.Elogin(user);
        return user1;
    }

    @Override
    public User stateCheck(User user) {
        User user1=empMapper.stateCheck(user);
        return user1;
    }

    @Override
    public List<OrdersList> eShowOrders(String empName) {
        List<OrdersList> ordersLists=empMapper.eShowOrders(empName);
        return ordersLists;
    }

    @Override
    public void eAcceptOrder(Long orderId, String empName) {
        empMapper.addOrders(orderId);
        empMapper.addEmpOrders(orderId,empName);
    }

    @Override
    public void arrive(Long orderId) {
        empMapper.arrive(orderId);
    }

    @Override
    public PageBean3 eShowOrders(String empName, int currentPage, int pageSize) {
        int count=empMapper.conCount(empName);
        int start=(currentPage-1)*pageSize;
        List<EmpOrders>userOrders=empMapper.conPage(empName,start,pageSize);
        PageBean3 pageBean=new PageBean3(count,userOrders);
        return pageBean;
    }

    @Override
    public Result eChangePassword(String oldPassword, String newPassword, String empName) {
        Long oldPassword1=empMapper.findOldPassword(oldPassword,empName);
        System.out.println(oldPassword1);
        if(oldPassword1==null){
            return new Result(0,"Error_OldPassword",null);
        }
        if(newPassword.length()<4||newPassword.length()>20){
            return new Result(0,"Error_Password",null);
        }
        empMapper.eChangePassword(oldPassword,newPassword,empName);
        return Result.success();
    }
}
